﻿package tests;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.Lib;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import fpc.AComponent;
import fpc.controls.buttons.AButton;
import fpc.controls.buttons.Button;
import fpc.containers.Container;
import fpc.controls.buttons.IButton;
import fpc.layouts.ExcessSpaceMode;
import fpc.layouts.FlowLayout;
import fpc.layouts.VLayout;
import fpc.layouts.HLayout;
import fpc.layouts.ILineLayout;
import fpc.FoolProofComponents;
import fpc.controls.Spacer;

class VBoxTest extends GenericTest
{	
	public function new() 
	{
		super();
	}
	
	var _container:Container<ILineLayout>;
	
	override function init()
	{
		FoolProofComponents.initStage(stage);
		
		var container = _container = new Container<ILineLayout>();
		container.addTo(this);
		container.layout = new VLayout();
		container.layout.gapY = 0;
		
		var layout = container.layout;
		layout.autoSize = false;
		
		layout.add(new Spacer().setXSize(100).setYSize(20, 100, null, 100));
		layout.add(new Spacer().setXSize(100).setYSize(20, 10, 30, 100));
		layout.add(new Spacer().setXSize(100).setYSize(20, 100, null, 100));
		layout.add(new Spacer().setXSize(100).setYSize(20, 10, 50, 100));
		layout.add(new Spacer().setXSize(100).setYSize(20, 100, null, 100));
		
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 12));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, 4, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 12));
		layout.add(new Spacer().setXSize(100).setYSize(10, 100, 5, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, 6, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, 7, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 100));
		layout.add(new Spacer().setXSize(100).setYSize(10, 12, null, 100));
		
		container.width = 300;
		
		var subContainer = new Container<ILineLayout>(new FlowLayout());
		subContainer.layout.autoSize = false;
		subContainer.width = 300;
		subContainer.height = 200;
		subContainer.percentsWidth = 100;
		subContainer.alignX = 1;
		layout.add(subContainer);
		
		var button = new Button('SubButton0');
		button.percentsWidth = 100;
		subContainer.layout.add(button);
		var button = new Button('SubButton1');
		button.percentsWidth = 50;
		subContainer.layout.add(button);
		var button = new Button('SubButton2');
		button.percentsWidth = 50;
		subContainer.layout.add(button);
		
		cast(layout, VLayout).excessSpaceMode = ExcessSpaceMode.UNIFORM;
	}
	
	/*override function init()
	{
		FoolProofComponents.initStage(stage);
		
		var container = _container = new Container<LineLayout>();
		container.addTo(this);
		container.layout = new VLayout();
		//container.layout.gapY = 0;
		
		var shape = new Shape();
		addChild(shape);
		cast(container.layout, VLayout).graphics = shape.graphics;
		
		var layout = container.layout;
		layout.autoSize = false;
		
		var button = new Button('Button0', onButtonClick);
		button.percentsHeight = 20;
		layout.add(button);
		var button = new Button('Button1');
		button.percentsHeight = 20;
		layout.add(button);
		var button = new Button('Button2');
		button.percentsHeight = 20;
		layout.add(button);
		var button = new Button('Button3');
		button.percentsHeight = 10;
		layout.add(button);
		var button = new Button('Button4');
		button.percentsHeight = 30;
		layout.add(button);
		var button = new Button('Button5');
		button.width = 80;
		button.alignX = 0;
		button.percentsHeight = 20;
		layout.add(button);
		
		layout.add(new Spacer().setXSize(100).setYSize(20, 100, null, 100));
		
		container.width = 300;
		
		var subContainer = new Container<LineLayout>(new FlowLayout());
		subContainer.layout.autoSize = false;
		subContainer.width = 300;
		subContainer.height = 200;
		//subContainer.percentsHeight = 100;
		subContainer.percentsWidth = 100;
		subContainer.alignX = 1;
		layout.add(subContainer);
		
		var button = new Button('SubButton0');
		button.percentsWidth = 100;
		subContainer.layout.add(button);
		var button = new Button('SubButton1');
		button.percentsWidth = 50;
		subContainer.layout.add(button);
		var button = new Button('SubButton2');
		button.percentsWidth = 50;
		subContainer.layout.add(button);
		
		var button = new Button('Button6');
		button.percentsHeight = 10;
		layout.add(button);
		var button = new Button('Button7');
		button.percentsHeight = 20;
		layout.add(button);
		var button = new Button('Button8');
		button.percentsWidth = 78;
		button.percentsHeight = 30;
		layout.add(button);
		var button = new Button('Button9');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
	}*/
	
	function init_()
	{
		FoolProofComponents.initStage(stage);
		
		var container = _container = new Container<ILineLayout>();
		container.addTo(this);
		container.layout = new VLayout();
		container.layout.gapY = 0;
		
		var layout = container.layout;
		layout.autoSize = false;
		
		var button = new Button('Button0', onButtonClick);
		layout.add(button);
		var button = new Button('Button1');
		layout.add(button);
		var button = new Button('Button2');
		layout.add(button);
		var button = new Button('Button3');
		button.percentsHeight = 1;
		layout.add(button);
		var button = new Button('Button4');
		layout.add(button);
		var button = new Button('Button5');
		button.width = 80;
		button.alignX = 0;
		layout.add(button);
		
		layout.add(new Spacer().setXSize(100).setYSize(20, 100, null, 100));
		
		container.width = 300;
		
		var subContainer = new Container<ILineLayout>(new FlowLayout());
		subContainer.layout.autoSize = false;
		subContainer.width = 300;
		subContainer.height = 200;
		subContainer.percentsHeight = 100;
		subContainer.percentsWidth = 100;
		subContainer.alignX = 1;
		layout.add(subContainer);
		
		var button = new Button('SubButton0');
		button.percentsWidth = 100;
		subContainer.layout.add(button);
		var button = new Button('SubButton1');
		button.percentsWidth = 50;
		subContainer.layout.add(button);
		var button = new Button('SubButton2');
		button.percentsWidth = 50;
		subContainer.layout.add(button);
		
		var button = new Button('Button6');
		button.percentsHeight = 10;
		layout.add(button);
		var button = new Button('Button7');
		button.percentsHeight = 20;
		layout.add(button);
		/*var button = new Button('Button8');
		button.percentsWidth = 78;
		layout.add(button);
		var button = new Button('Button9');
		button.percentsWidth = 100;
		layout.add(button);*/
	}
	
	var _heightFlag:Bool;
	
	function onButtonClick(button:IButton)
	{
		button.height = _heightFlag ? 100 : 20;
		_heightFlag = !_heightFlag;
	}
	
	override function resize(width, height)
	{
		var time = Lib.getTimer();
		
		_container.width = width;
		_container.height = height;
		
		trace(Lib.getTimer() - time);
		
		var g = graphics;
		g.clear();
		if (_container.height > stage.stageHeight + .1)
		{
			g.clear();
			g.beginFill(0x7ef000);
			g.drawRect(0, 0, _container.width, _container.height);
			g.endFill();
		}
	}
}